from typing import List

from redis import Redis

from ..graph.base import BaseGraph
from ..graph.nodes import *
from ..models.graph import GraphRequest
from ..parser.xml_parser import XmlToolResultParser


class DeepResearchGraph(BaseGraph):
    """
    专业的深度研究及对话助手，能够高效精准地解决用户复杂的信息需求和研究问题。
    具备信息检索、深度分析、知识整合、批判性思考和研究规划等核心能力，能够从互联网和各种数据源获取信息，
    对复杂问题进行多角度分析，并将不同来源的信息整合成连贯、全面的回答。
    """

    def __init__(self,
                 redis: Redis = None,
                 nodes: List[BaseNodes] = [],
                 graph_name="agent_deepresearch_",
                 agent_template: str = "agent_deepresearch",
                 **kwargs):
        super().__init__(graph_name=graph_name,
                         agent_template=agent_template,
                         redis=redis,
                         **kwargs)
        self.nodes = nodes if nodes else [WebNodes(), AskUserNodes()]
        self.parser = XmlToolResultParser(tools=self.get_nodes_schema())

    async def get_system_template(self, request: GraphRequest, state=None, template_type: str = None):
        """
        Override base implementation to add coder-specific default values.
        """
        if "custom_instructions" not in request.kwargs:
            request.kwargs["custom_instructions"] = ""

        return await super().get_system_template(request=request, state=state, template_type=template_type)
